<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="设备编号" prop="machineId">
        <el-input
          v-model="queryParams.machineId"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作账号" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作人员" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择" clearable style="width: 240px">
          <el-option
            v-for="item in typeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="操作日期" style="width: 308px">
        <el-date-picker
          v-model="dateRange"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="设备编号" align="center" prop="machineId" />
      <el-table-column label="操作账号" align="center" prop="account" />
      <el-table-column label="操作人员" align="center" prop="userName" />
      <el-table-column label="操作类型" align="center" prop="type">
        <template #default="{ row }">
          <span>{{ typeList.find((i) => i.value === row.type).label }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作日期" align="center" prop="creartTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.creartTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script setup>
import { getOtherLogApi } from '@/api/monitor/otherLog'
const { proxy } = getCurrentInstance()

const showSearch = ref(true)
const queryParams = ref({
  account: null,
  userName: null,
  machineId: null,
  startTime: null,
  endTime: null,
  type: null,
  pageNum: 1,
  pageSize: 10
})
const dateRange = ref([])
const typeList = [
  { value: 1, label: '同步计划' },
  { value: 2, label: '报损' },
  { value: 3, label: '修改库存' }
]

const queryRef = ref()
const list = ref([])
const loading = ref(false)
const total = ref(0)
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}
function resetQuery() {
  proxy.resetForm('queryRef')
  queryParams.value.startTime = null
  queryParams.value.endTime = null
  dateRange.value = []
  handleQuery()
}
function getList() {
  console.log(queryParams.value.dateRange)
  if (dateRange.value.length) {
    queryParams.value.startTime = dateRange.value[0]
    queryParams.value.endTime = dateRange.value[1]
  }
  getOtherLogApi(queryParams.value).then((res) => {
    console.log(res)
    list.value = res?.rows || []
    total.value = res?.total || 0
  })
}
getList()
</script>

<style lang="scss" scoped></style>
